import { setItem, getItem } from "@/utils/auth";
import { login } from '@/api/users'
const Key = "yanxuan-token"
const Login = "isLogin"
const User = "Userinfo"
export default {
    namespaced: true,
    state: () => {
        return {
            userinfo: {
                token: getItem(Key),
                islogin: getItem(Login) || false,
            },
            ruleForm: getItem(User) || {}

        }
    },
    mutations: {
        isLogin(state, payload) {
            state.userinfo.islogin = payload
            setItem(Login, state.userinfo.isLogin)
            console.log(2, state.userinfo.isLogin);
        },
        getRegister(state, payload) {

        }
    },
    actions: {
        async login({ commit }, payload) {
            const res = await login()
            const form = res[1]
            console.log(1, form);
            console.log(payload);
            if (form === payload) {
                commit('isLogin', true)
            } else if (form === '') {
                commit('isLogin', false)
            } else {
                return
            }
        },
        updateNameAsync({ commit }, payload) {
            setTimeout(() => {
                commit('updateName', payload)
            }, 2000);
        }
    },
    getters: {

    }
}